__author__ = 'Brandon Corfman'

import unittest
from game import Game
from path import Goal, Path
from humanagent import HumanAgent
from dwarves import Saboteur, GoldDigger

class TestScoringForGoldDiggers(unittest.TestCase):
    """
    A simple test to set the game to a winning state for the GoldDiggers by creating a valid
    path to the goal and assessing the nuggets distributed.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        dwarf_types = [GoldDigger, Saboteur, GoldDigger]
        for i, name in enumerate(['Ava', 'Brianna', 'Chelsea']):
            self.game.add_player(HumanAgent, dwarf_types[i], name)
        self.game.board.goals = [Goal('SW', 'stone'), Goal('NSEW', 'gold'), Goal('NW', 'stone')]
        self.game.board.path[2][8] = self.game.board.goals[0]
        self.game.board.path[4][8] = self.game.board.goals[1]
        self.game.board.path[6][8] = self.game.board.goals[2]
        for col in range(2, 8):
            self.game.board.set_path(self.game.players[2].agent, 4, col, Path('EW', 'EW'))

    def testScoring(self):
        self.game.calc_player_scores()
        player = self.game.players[0]
        if isinstance(player.dwarf, GoldDigger):
            self.assertGreater(player.nuggets, 0)
        else:
            self.assertEqual(player.nuggets, 0)

class TestScoringForSaboteurs(unittest.TestCase):
    """
    A simple test to set the game to a winning state for the Saboteurs by making all players pass.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        dwarf_types = [Saboteur, GoldDigger, Saboteur]
        for i, name in enumerate(['Ava', 'Brianna', 'Chelsea']):
            self.game.add_player(HumanAgent, dwarf_types[i], name)
        for player in self.game.players:
            player.passed = True

    def testScoring(self):
        self.game.calc_player_scores()
        for player in self.game.players:
            if isinstance(player.dwarf, Saboteur):
                self.assertGreater(player.nuggets, 0)
            else:
                self.assertEqual(player.nuggets, 0)

if __name__ == '__main__':
    unittest.main()
